package com.leigang.java.code.mulithread.thread;

/**
 * @author leig-a
 */
public class SellTicketSynchronized {
    /**
     *  有100张票
     */
    private int tickets = 100;

    /**
     *    买票方法，模拟买票的动作
     */
    public synchronized void sell() {
        if (tickets > 0) {
            System.out.println(Thread.currentThread().getName() + "，" +
                    "已经卖出了第（" + tickets-- + "）张票，" +
                    "还剩（" + tickets + "）张票。");
        }
    }
}
